<script setup>
import AsideCard from './asideCard.vue';
import { inject } from 'vue';

const cardData = {
    title: '主题色',
    icon: 'Histogram'
};

const { themeColor } = inject('data');

// 预设主题色 - 调整为更符合黑色主题的配色
const presetColors = [
    '#000',
    '#222',
    '#7F56D9', // 紫色
    '#3E90F0', // 蓝色
    '#12B76A', // 绿色
    '#F79009', // 橙色
    '#F04438', // 红色
    '#9E77ED', // 紫色
    '#17B26A', // 绿色
    '#FDB022', // 黄色
];

// 处理颜色选择
const handleColorChange = (color) => {
    themeColor.color=color;
};
</script>

<template>
    <div class="aside-layout-main dark-theme">
        <AsideCard :title="cardData.title" :icon="cardData.icon">
            <div class="color-picker-container">
                <h4 class="section-title">预设颜色</h4>
                <div class="preset-colors">
                    <div 
                        v-for="color in presetColors" 
                        :key="color"
                        class="color-swatch"
                        :style="{ backgroundColor: color }"
                        @click="handleColorChange(color)"
                        :class="{ active: themeColor.color === color }"
                    ></div>
                </div>
                
                <h4 class="section-title">自定义颜色</h4>
                <div class="custom-color-picker">
                    <input 
                        type="color" 
                        :value="themeColor.color" 
                        @input="handleColorChange($event.target.value)"
                        class="color-input"
                    />
                    <span class="color-value">{{ themeColor.color }}</span>
                </div>
            </div>
        </AsideCard>
    </div>
</template>

<style scoped>
/* 黑色主题样式 */
.dark-theme {
    --bg-color: #1a1a1a;
    --card-bg: #242424;
    --text-color: #e0e0e0;
    --border-color: #333;
    --hover-color: #2d2d2d;
    --active-border: #7F56D9;
}

.color-picker-container {
    padding: 12px;
    background-color: var(--card-bg);
    border-radius: 8px;
}

.section-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    margin: 12px 0 8px;
}

.preset-colors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.color-swatch {
    width: 40px;  /* 固定宽度 */
    height: 40px; /* 固定高度 */
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid var(--border-color);
    box-sizing: border-box;
}

.color-swatch:hover {
    transform: scale(1.05);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
}

.color-swatch.active {
    border-color: var(--active-border);
    box-shadow: 0 0 0 2px rgba(127, 86, 217, 0.3);
}

.custom-color-picker {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.color-input {
    width: 40px;  /* 与预设颜色相同大小 */
    height: 40px; /* 与预设颜色相同大小 */
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    border-radius: 6px;
    border: 2px solid var(--border-color);
}

.color-input::-webkit-color-swatch {
    border-radius: 4px;
    border: none;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-value {
    font-size: 13px;
    color: var(--text-color);
    user-select: all;
    opacity: 0.8;
}

/* 适配暗色主题的滚动条 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}
</style>